package cn.stylefeng.guns.sys.modular.system.service;

import cn.hutool.core.collection.CollectionUtil;
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.auth.model.LoginUser;
import cn.stylefeng.guns.base.pojo.node.MenuNode;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.core.constant.Const;
import cn.stylefeng.guns.sys.core.constant.cache.CacheKey;
import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory;
import cn.stylefeng.guns.sys.core.constant.state.ManagerStatus;
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum;
import cn.stylefeng.guns.sys.core.util.DefaultImages;
import cn.stylefeng.guns.sys.core.util.RedisUtils;
import cn.stylefeng.guns.sys.core.util.SaltUtil;
import cn.stylefeng.guns.sys.modular.system.entity.BtyArchives;
import cn.stylefeng.guns.sys.modular.system.entity.Emp;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.RoleIdEnum;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.entity.UserPos;
import cn.stylefeng.guns.sys.modular.system.factory.UserFactory;
import cn.stylefeng.guns.sys.modular.system.mapper.UserMapper;
import cn.stylefeng.guns.sys.modular.system.model.UserDto;
import cn.stylefeng.guns.sys.modular.system.model.params.EmpParam;
import cn.stylefeng.guns.sys.modular.system.model.params.UserAddParam;
import cn.stylefeng.guns.sys.modular.system.model.params.UserParam;
import cn.stylefeng.guns.sys.modular.system.model.result.WxInfoResult;
import cn.stylefeng.roses.core.datascope.DataScope;
import cn.stylefeng.roses.core.reqres.response.ErrorResponseData;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.reqres.response.SuccessResponseData;
import cn.stylefeng.roses.core.util.HttpContext;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 管理员表 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2018-12-07
 */
@Service
public class UserService extends ServiceImpl<UserMapper, User> {

    @Autowired
    private MenuService menuService;

    @Autowired
    private UserPosService userPosService;
    @Autowired
    private EmpService empService;

    @Autowired
    private BtyArchivesService btyArchivesService;



    /**
     * 添加用戶
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:51
     */
    @Transactional(rollbackFor = Exception.class)
    public void addUser(UserDto user) {

        // 判断账号是否重复
        User theUser = this.getByAccount(user.getAccount());
        if (theUser != null) {
            throw new ServiceException(BizExceptionEnum.USER_ALREADY_REG);
        }

        // 完善账号信息
        String salt = SaltUtil.getRandomSalt();
        String password = SaltUtil.md5Encrypt(user.getPassword(), salt);

        User newUser = UserFactory.createUser(user, password, salt);
        this.save(newUser);

        //添加职位关联
        addPosition(user.getPosition(), newUser.getUserId());
    }

    /**
     * 修改用户
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:53
     */
    @Transactional(rollbackFor = Exception.class)
    public void editUser(UserDto user) {
        User oldUser = this.getById(user.getUserId());

        if (LoginContextHolder.getContext().hasRole(Const.ADMIN_NAME)) {
            this.updateById(UserFactory.editUser(user, oldUser));
        } else {
            this.assertAuth(user.getUserId());
            LoginUser shiroUser = LoginContextHolder.getContext().getUser();
            if (shiroUser.getId().equals(user.getUserId())) {
                this.updateById(UserFactory.editUser(user, oldUser));
            } else {
                throw new ServiceException(BizExceptionEnum.NO_PERMITION);
            }
        }

        //删除职位关联
        userPosService.remove(new QueryWrapper<UserPos>().eq("user_id", user.getUserId()));

        //添加职位关联
        addPosition(user.getPosition(), user.getUserId());
    }

    /**
     * 删除用户
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:54
     */
    @Transactional(rollbackFor = Exception.class)
    public void deleteUser(Long userId) {

        //不能删除超级管理员
        if (userId.equals(Const.ADMIN_ID)) {
            throw new ServiceException(BizExceptionEnum.CANT_DELETE_ADMIN);
        }
        this.assertAuth(userId);
        this.setStatus(userId, ManagerStatus.DELETED.getCode());

        //删除职位关联
        userPosService.remove(new QueryWrapper<UserPos>().eq("user_id", userId));
    }

    /**
     * 修改用户状态
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:45
     */
    public int setStatus(Long userId, String status) {
        return this.baseMapper.setStatus(userId, status);
    }

    /**
     * 修改密码
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:45
     */
    public void changePwd(String oldPassword, String newPassword) {
        Long userId = LoginContextHolder.getContext().getUser().getId();
        User user = this.getById(userId);

        String oldMd5 = SaltUtil.md5Encrypt(oldPassword, user.getSalt());

        if (user.getPassword().equals(oldMd5)) {
            String newMd5 = SaltUtil.md5Encrypt(newPassword, user.getSalt());
            user.setPassword(newMd5);
            this.updateById(user);
        } else {
            throw new ServiceException(BizExceptionEnum.OLD_PWD_NOT_RIGHT);
        }
    }

    /**
     * 根据条件查询用户列表
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:45
     */
    public Page<Map<String, Object>> selectUsers(DataScope dataScope, String name, String beginTime, String endTime, Long deptId) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.selectUsers(page, dataScope, name, beginTime, endTime, deptId);
    }

    /**
     * 设置用户的角色
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:45
     */
    public int setRoles(Long userId, String roleIds) {
        return this.baseMapper.setRoles(userId, roleIds);
    }

    /**
     * 通过账号获取用户
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:46
     */
    public User getByAccount(String account) {
        return this.baseMapper.getByAccount(account);
    }

  public   User getAccount(@Param("account") String account){
      return this.baseMapper.getAccount(account);
  }

    /**
     * 获取用户菜单列表
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:46
     */
    public List<Map<String, Object>> getUserMenuNodes(List<Long> roleList) {
        Long userId = LoginContextHolder.getContext().getUser().getId();
        if (roleList == null || roleList.size() == 0) {
            return new ArrayList<>();
        } else {
            List<MenuNode> menus = menuService.getMenusByRoleIds(roleList);

            //定义不同系统分类的菜单集合
            ArrayList<Map<String, Object>> lists = new ArrayList<>();

            //根据当前用户包含的系统类型，分类出不同的菜单
            List<Map<String, Object>> systemTypes = LoginContextHolder.getContext().getUser().getSystemTypes();
            for (Map<String, Object> systemType : systemTypes) {

                //当前遍历系统分类code
                String systemCode = (String) systemType.get("code");

                //获取当前系统分类下菜单集合
                ArrayList<MenuNode> originSystemTypeMenus = new ArrayList<>();
                for (MenuNode menu : menus) {

                    if (menu.getSystemType().equals(systemCode)) {
                        if(ToolUtil.isNotEmpty(menu.getWebFlag())){
                            if(menu.getWebFlag().equals("Y")){
                                ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
                                String token = (String)servletRequestAttributes.getRequest().getSession().getAttribute("token");
                                if(token==null || token.equals("") || token.equals("null")){
                                    Cookie[] cookies = HttpContext.getRequest().getCookies();
                                    for (Cookie cookie : cookies) {
                                        if ("Authorization".equalsIgnoreCase(cookie.getName())) {
                                            token = cookie.getValue();
                                        }
                                    }
                                }
                                String webToken=menu.getUrl()+"&token="+token+"&client=yyxt";
                                menu.setUrl(webToken);
                            }
                        }
                        originSystemTypeMenus.add(menu);
                    }
                }

                //拼接存放key为系统分类编码，value为该分类下菜单集合的map
                HashMap<String, Object> map = new HashMap<>();
                List<MenuNode> treeSystemTypeMenus = MenuNode.buildTitle(originSystemTypeMenus);
                map.put("systemType", systemCode);
                map.put("menus", treeSystemTypeMenus);
                lists.add(map);
            }

            return lists;
        }
    }

    /**
     * 判断当前登录的用户是否有操作这个用户的权限
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:44
     */
    public void assertAuth(Long userId) {
        if (LoginContextHolder.getContext().isAdmin()) {
            return;
        }
        List<Long> deptDataScope = LoginContextHolder.getContext().getDeptDataScope();
        User user = this.getById(userId);
        Long deptId = user.getDeptId();
        if (deptDataScope.contains(deptId)) {
            return;
        } else {
            throw new ServiceException(BizExceptionEnum.NO_PERMITION);
        }
    }

    /**
     * 刷新当前登录用户的信息
     *
     * @author fengshuonan
     * @Date 2019/1/19 5:59 PM
     */
    public void refreshCurrentUser() {
        //TODO 刷新
    }

    /**
     * 获取用户的基本信息
     *
     * @author fengshuonan
     * @Date 2019-05-04 17:12
     */
    public Map<String, Object> getUserInfo(Long userId) {
        User user = this.getById(userId);
        Map<String, Object> map = UserFactory.removeUnSafeFields(user);

        HashMap<String, Object> hashMap = CollectionUtil.newHashMap();
        hashMap.putAll(map);
        hashMap.put("roleName", ConstantFactory.me().getRoleName(user.getRoleId()));
        hashMap.put("deptName", ConstantFactory.me().getDeptName(user.getDeptId()));

        return hashMap;
    }

    /**
     * 获取用户首页信息
     *
     * @author fengshuonan
     * @Date 2019/10/17 16:18
     */
    public Map<String, Object> getUserIndexInfo() {

        //获取当前用户角色列表
        LoginUser user = LoginContextHolder.getContext().getUser();
        List<Long> roleList = user.getRoleList();

        //用户没有角色无法显示首页信息
        if (roleList == null || roleList.size() == 0) {
            return null;
        }

        List<Map<String, Object>> menus = this.getUserMenuNodes(roleList);

        HashMap<String, Object> result = new HashMap<>();
        result.put("menus", menus);
        result.put("avatar", DefaultImages.defaultAvatarUrl());
        result.put("name", user.getName());

        return result;
    }

    /**
     * 获取用户首页信息
     *
     * @author fengshuonan
     * @Date 2019/10/17 16:18
     */
    public Map<String, Object> getUserIndexInfo(Integer version) {

        //获取当前用户角色列表
        LoginUser user = LoginContextHolder.getContext().getUser();
        List<Long> roleList = user.getRoleList();

        //用户没有角色无法显示首页信息
        if (roleList == null || roleList.size() == 0) {
            return null;
        }

        List<Map<String, Object>> menus = this.getUserMenuNodes(roleList, version);

        HashMap<String, Object> result = new HashMap<>();
        result.put("menus", menus);
        result.put("avatar", DefaultImages.defaultAvatarUrl());
        result.put("name", user.getName());

        return result;
    }

    /**
     * 获取用户菜单列表
     *
     * @author fengshuonan
     * @Date 2018/12/24 22:46
     */
    public List<Map<String, Object>> getUserMenuNodes(List<Long> roleList, Integer version) {
        Long userId = LoginContextHolder.getContext().getUser().getId();
        if (roleList == null || roleList.size() == 0) {
            return new ArrayList<>();
        } else {
            List<MenuNode> menus = menuService.getMenusByRoleIds(roleList, version);

            //定义不同系统分类的菜单集合
            ArrayList<Map<String, Object>> lists = new ArrayList<>();

            //根据当前用户包含的系统类型，分类出不同的菜单
            List<Map<String, Object>> systemTypes = LoginContextHolder.getContext().getUser().getSystemTypes();
            for (Map<String, Object> systemType : systemTypes) {

                //当前遍历系统分类code
                String systemCode = (String) systemType.get("code");

                //获取当前系统分类下菜单集合
                ArrayList<MenuNode> originSystemTypeMenus = new ArrayList<>();
                for (MenuNode menu : menus) {

                    if (menu.getSystemType().equals(systemCode)) {
                        if(ToolUtil.isNotEmpty(menu.getWebFlag())){
                            if(menu.getWebFlag().equals("Y")){
                                ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
                                String token = (String)servletRequestAttributes.getRequest().getSession().getAttribute("token");
                                if(token==null || token.equals("") || token.equals("null")){
                                    Cookie[] cookies = HttpContext.getRequest().getCookies();
                                    for (Cookie cookie : cookies) {
                                        if ("Authorization".equalsIgnoreCase(cookie.getName())) {
                                            token = cookie.getValue();
                                        }
                                    }
                                }
                                String webToken=menu.getUrl()+"&token="+token+"&client=yyxt";
                                menu.setUrl(webToken);
                            }
                        }
                        originSystemTypeMenus.add(menu);
                    }
                }

                //拼接存放key为系统分类编码，value为该分类下菜单集合的map
                HashMap<String, Object> map = new HashMap<>();
                List<MenuNode> treeSystemTypeMenus = MenuNode.buildTitle(originSystemTypeMenus);
                map.put("systemType", systemCode);
                map.put("menus", treeSystemTypeMenus);
                lists.add(map);
            }

            return lists;
        }
    }

    /**
     * 添加职位关联
     *
     * @author fengshuonan
     * @Date 2019-06-28 13:35
     */
    private void addPosition(String positions, Long userId) {
        if (ToolUtil.isNotEmpty(positions)) {
            String[] position = positions.split(",");
            for (String item : position) {

                UserPos entity = new UserPos();
                entity.setUserId(userId);
                entity.setPosId(Long.valueOf(item));

                userPosService.save(entity);
            }
        }
    }

    /**
     * 根据手机查找用户
     * @param phone
     * @return
     */
    public List<User> getUserByphone(String phone){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone",phone).or().eq("account",phone).ne("status",ManagerStatus.DELETED.getCode());
        List<User> users = baseMapper.selectList(wrapper);
        return users;
    }

    /**
     * 选择办理人
     *
     * @author fengshuonan
     * @Date 2019-08-27 19:07
     */
    public IPage listUserAndRoleExpectAdmin(Page pageContext) {
        return baseMapper.listUserAndRoleExpectAdmin(pageContext);
    }

    public List<String> listOpenidsByRole(Long roleid) {
        return baseMapper.listOpenidsByRole(roleid);
    }

    public List<String> listOpenidsByPhone(Long roleId,String phone) {
        return baseMapper.listOpenidsByPhone(roleId,phone);
    }

    public List<WxInfoResult> listWxInfoByRole(Long roleid) {
        return baseMapper.listWxInfoByRole(roleid);
    }

    public Map<String, Object> getWxByUserid(Long userId) {
        return baseMapper.getWxByUserid(userId);
    }


    @Transactional(rollbackFor = Exception.class)
    public ResponseData createUserAndSetRole(String paramInfo) {
        //paramInfo格式为：gczhzc，账号名称，姓名，密码，密码，手机号，角色
        String[] userInfo = paramInfo.split("，");
        if (userInfo.length != 7) {
            return new ErrorResponseData("您输入的注册信息有误，请重新输入。");
        }
        for (String info : userInfo) {
            if (info.equals("")) {
                return new ErrorResponseData("您输入的注册信息存在空值，请提交正确信息。");
            }
        }

        UserAddParam userAddParam = new UserAddParam();
        userAddParam.setAccount(userInfo[1]);
        userAddParam.setName(userInfo[2]);
        userAddParam.setPassword(userInfo[3]);
        userAddParam.setConfirmPassword(userInfo[4]);
        userAddParam.setPhone(userInfo[5]);
        userAddParam.setRoleIds(userInfo[6]);
        return addUserAndSetRole(userAddParam);
    }

    @Transactional(rollbackFor = Exception.class)
    public ResponseData addUserAndSetRole(UserAddParam userAddParam) {
        // 判断账号是否重复
        User theUser = this.getByAccount(userAddParam.getAccount());
//        BtyArchives btyArchives = btyArchivesService.getOne(new QueryWrapper<BtyArchives>().eq("tel",userAddParam.getPhone()));
        EmpParam param=new EmpParam();
        param.setTel(userAddParam.getPhone());
        List<Emp> empList = empService.listParam(param);
        if (theUser != null) {
            return new ErrorResponseData("添加失败，您输入的账号名称已被使用，请换一个账号名称，重新注册。");
        }
        if (userAddParam.getPassword().length() < 6 || userAddParam.getPassword().length() > 12) {
            return new ErrorResponseData("您输入的注册信息有误，密码必须6到12位且不能出现空格。");
        }
        if (!userAddParam.getPassword().equals(userAddParam.getConfirmPassword())) {
            return new ErrorResponseData("您输入的注册信息有误，您两次输入的密码信息不一致。");
        }
        if (userAddParam.getPhone().equals("")) {
            return  new ErrorResponseData("您输入的注册信息有误,手机号不允许为空");
        }
        if (userAddParam.getPhone().length()!=11) {
            return  new ErrorResponseData("您输入的注册信息有误,手机号必须为11位数字");
        }
        if (ToolUtil.isEmpty(empList)) {
            return  new ErrorResponseData("注册失败，您不是公司员工，无法注册，请联系公司人事进行员工建档");
        }
        //手机号不允许重复
        UserParam userParam = new UserParam();
        userParam.setPhone(userAddParam.getPhone());
        List<User> userList = this.baseMapper.findUsersByParam(userParam);
        if (CollectionUtil.isNotEmpty(userList)) {
            return new ErrorResponseData("您输入的注册信息有误,已存在使用该手机号的用户");
        }
        if (RoleIdEnum.getByMsg(userAddParam.getRoleIds().trim()) == null) {
            return new ErrorResponseData("您输入的注册信息有误，您输入的角色不存在。角色只能为：开发人员,开发总监,工程总监,营运总监,营运经理,督导,网上建店负责人,工程部，店长，其中一个。");
        }
        RoleIdEnum roleEnum = RoleIdEnum.getByMsg(userAddParam.getRoleIds().trim());
        userAddParam.setRoleIds(roleEnum.getCode().toString());

        // 完善账号信息
        String salt = SaltUtil.getRandomSalt();
        String password = SaltUtil.md5Encrypt(userAddParam.getPassword(), salt);

        //添加用户
        UserDto userDto = new UserDto();
        userDto.setAccount(userAddParam.getAccount().trim());
        userDto.setName(userAddParam.getName().trim());
        userDto.setPassword(userAddParam.getPassword().trim());
        userDto.setPhone(userAddParam.getPhone().trim());
        User newUser = UserFactory.createUser(userDto, password, salt);
        this.save(newUser);

        //获取userId
        User saveUser = getByAccount(userAddParam.getAccount());
        Long userId = saveUser.getUserId();
        //不能修改超级管理员
        if (userId.equals(Const.ADMIN_ID)) {
            return  new ErrorResponseData("不能修改超级管理员角色");
        }
        setRoles(userId, userAddParam.getRoleIds());
        return  new SuccessResponseData("工程账号注册成功");
    }


    /**
     * 修改工程注册账号
     *
     * @author jiangge
     * @Date 2020/10/07 19:00
     */
    public String changeAccountInfo(String content) {
        String[] userInfo = content.split("，");
        //TODO-1 修改工程账号密码
        if (userInfo[0].equals("gczhxgmm")) {
            if (userInfo.length != 5) {
                return "您提交的信息有误，请重新输入。修改工程账号密码，发送信息格式为：gczhxgmm，账号名称，旧密码，新密码，新密码";
            }
            if (!userInfo[3].equals(userInfo[4])) {
                return "您输入的信息有误，第4第5项应为新密码信息，两次输入的新密码信息不一致。";
            }
            UserAddParam userAddParam = new UserAddParam();
            userAddParam.setAccount(userInfo[1]);
            userAddParam.setOldPassword(userInfo[2]);
            userAddParam.setNewPassword(userInfo[3]);
            //获取userId
            User user = getByAccount(userAddParam.getAccount().trim());
            if (user == null) {
                return "该账号不存在，请输入正确的账号信息";
            }
            if (user.getUserId().equals(Const.ADMIN_ID)) {
                return "不能修改超级管理员密码";
            }
            String oldMd5 = SaltUtil.md5Encrypt(userAddParam.getOldPassword().trim(), user.getSalt());
            if (user.getPassword().equals(oldMd5)) {
                String newMd5 = SaltUtil.md5Encrypt(userAddParam.getNewPassword().trim(), user.getSalt());
                user.setPassword(newMd5);
                this.updateById(user);
                return "修改密码成功";
            } else {
                return "原密码不正确,请重新发送修改密码信息";
            }
        }
        //TODO-2 修改工程账号手机号
        if (userInfo[0].equals("gczhxgsjh")) {
            if (userInfo.length != 3) {
                return "您提交的账号信息有误，请重新输入。修改工程账号手机号，发送发送信息格式为：gczhxgsjh，账号名称，新手机号";
            }
            UserAddParam userAddParam = new UserAddParam();
            userAddParam.setAccount(userInfo[1]);
            userAddParam.setPhone(userInfo[2]);
            //获取userId
            User user = getByAccount(userAddParam.getAccount().trim());
            if (user == null) {
                return "该账号不存在，请输入正确的账号信息";
            }
            if (user.getUserId().equals(Const.ADMIN_ID)) {
                return "不能修改超级管理员手机号";
            }
            //手机号不允许重复
            UserParam userParam = new UserParam();
            userParam.setPhone(userInfo[2]);
            List<User> userList = this.baseMapper.findUsersByParam(userParam);
            if (CollectionUtil.isNotEmpty(userList)) {
                return "您提交的账号信息有误,已存在使用该手机号的用户";
            }
            user.setPhone(userAddParam.getPhone());
            this.updateById(user);
            return "修改手机号成功";
        }
        //TODO-3 修改工程账号角色
        if (userInfo[0].equals("gczhxgjs")) {
            if (userInfo.length != 3) {
                return "您提交的账号信息有误，请重新输入。修改工程账号角色格式为：gczhxgjs,账号名称，角色名称";
            }
            UserAddParam userAddParam = new UserAddParam();
            userAddParam.setAccount(userInfo[1]);
            if (RoleIdEnum.getByMsg(userInfo[2].trim()) == null) {
                return "您提交的账号信息有误，您输入的角色不存在。角色只能为：开发人员,开发总监,工程总监,营运总监,营运经理,督导,网上建店负责人,工程部，店长，其中一个。";
            }
            userAddParam.setRoleIds(RoleIdEnum.getByMsg(userInfo[2].trim()).getCode().toString());
            //获取userId
            User user = getByAccount(userAddParam.getAccount().trim());
            if (user == null) {
                return "该账号不存在，请输入正确的账号信息";
            }
            if (user.getUserId().equals(Const.ADMIN_ID)) {
                return "不能修改超级管理员角色";
            }
            user.setRoleId(userAddParam.getRoleIds());
            this.updateById(user);
            return "修改角色成功";
        }

        return "";
    }

    //查询人事部openID
    public List<String> listOpenids(Long deptId) {
        return baseMapper.listOpenids(deptId);
    }



    /**
     * 查询所有用户的姓名
     * @return
     */
//    public List<User>nameList(){
//        return baseMapper.nameList();
//    }


}
